package com.ld.security.server.admin.modules.ge.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.ld.security.common.core.anno.IdKey;
import com.ld.security.common.core.base.column.MapJson;
import com.ld.security.common.mybatis.anno.LabelKeys;
import com.ld.security.common.mybatis.anno.SqlKey;
import com.ld.security.common.mybatis.base.entity.ESortEntity;
import com.ld.security.common.mybatis.base.entity.LabelMap;
import com.ld.security.common.mybatis.base.entity.SuperEntity;
import com.ld.security.common.mybatis.base.vo.ProxyVo;
import com.ld.security.common.mybatis.constant.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@TableName("ge_field")
@ApiModel("模型字段")
@Data
public class GeFieldEntity  extends SuperEntity implements ESortEntity,LabelMap,ProxyVo
{

    @SqlKey(SqlCondition.eq)
    @ApiModelProperty("模型")
    private String modelId;



    @SqlKey(SqlCondition.like)
    @ApiModelProperty("标题")
    private String label;

    @SqlKey(SqlCondition.like)
    @ApiModelProperty("字段名")
    private String fieldName;



    @LabelKeys
    @SqlKey
    @ApiModelProperty("运算类型")
    private SqlCondition sqlKey;

    @SqlKey
    @ApiModelProperty("顺序值")
    private Integer sortVal;

    @ApiModelProperty("配置")
    private MapJson config;

    @ApiModelProperty("表明")
    private String tableName;

    @ApiModelProperty("列明")
    private String columnName;

    private MapJson labelMap;

    /**
     * 当编码相同时，只能显示一个字段
     * 默认编码就是字段名
     *
     */
    @SqlKey
    @ApiModelProperty("分组编码")
    private String groupCode;


    @LabelKeys
    @SqlKey
    @ApiModelProperty("分组类型")
    private GroupTypeConstant groupType;

    @LabelKeys
    @SqlKey
    @ApiModelProperty("字段类型")
    private FieldTypeConstant fieldType;

    @LabelKeys
    @SqlKey
    @ApiModelProperty("数字类型")
    private NumberTypeConstant numberType;

    /**
     * 主要给日期字段格式化用
     */
    @LabelKeys
    @ApiModelProperty("日期格式化")
    private DateTypeConstant dateType;


    /**
     * 格子为单位
     * 就是点击事件
     */
    @ApiModelProperty("点击函数编号")
    private String clickFuncId;

    /**
     * 格子为单位
     * 数据加样式用
     */
    @ApiModelProperty("展示函数编号")
    private String showFuncId;

    @ApiModelProperty("计算脚本")
    private String computedFunc;

    @LabelKeys(GeCompEntity.class)
    @ApiModelProperty("组件编号")
    private String compId;



    private static GeFieldEntity field;



    @IdKey({"modelId","fieldName"})
    @Override
    public String getId() {
        return super.getId();
    }

    @Override
    public void saveBefore() {
     // if(columnName != null){
       //   this.tableName=this.columnName.split("\\.")[0];
      //}

    }

    public boolean eqField(GeFieldEntity geField){
        if(this.columnName.equals(geField.columnName)){
            return true;
        }
        return false;
    }



}
